using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CDStore3Tiers;

namespace CuaHangDiaNhac
{
    public partial class Form1 : Form
    {
        private List<AnnualRevenue> m_revenueList;
        DateTime batdau = DateTime.Now;
        DateTime ketthuc = DateTime.Now;
        public Form1(DateTime bd, DateTime kt)
        {
            InitializeComponent();
            batdau = bd;
            ketthuc = kt;
        }
        private void InitRevenueList()
        {
            if (batdau == ketthuc)
            {
                m_revenueList = new List<AnnualRevenue>();
                int doanhthu = XuLyThongKe.DoanhThuNgay(batdau);              
                m_revenueList.Add(new AnnualRevenue("("+batdau.ToShortDateString()+")", doanhthu));
            }
            else
            {
                if (batdau.Month == ketthuc.Month && batdau.Year == ketthuc.Year)
                {
                    m_revenueList = new List<AnnualRevenue>();
                    int doanhthu = XuLyThongKe.Doanhthu_Khoangtg(batdau, ketthuc);
                    m_revenueList.Add(new AnnualRevenue(batdau.ToShortDateString() + "\t -" + ketthuc.ToShortDateString() , doanhthu));
                }
                else
                {
                    if (batdau.Year == ketthuc.Year)
                    {
                        m_revenueList = new List<AnnualRevenue>();
                        DateTime j = batdau;
                        int ngaybd = j.Day, thangbd = j.Month, nambd = j.Year;
                        for (int k = thangbd; k <= ketthuc.Month; k++)
                        {
                            DateTime dulieudau = new DateTime(nambd, k, ngaybd);
                            //  DateTime d = new DateTime()
                            int doanhthu = 0;
                            doanhthu = XuLyThongKe.DoanhthuThang(dulieudau);
                           
                                m_revenueList.Add(new AnnualRevenue(dulieudau.Month.ToString() + "/" + dulieudau.Year.ToString()+":"+doanhthu, doanhthu));
                        }
                    }
                    else
                    {
                        m_revenueList = new List<AnnualRevenue>();
                        DateTime j = batdau;
                        int ngaybd = j.Day, thangbd = j.Month, nambd = j.Year;
                        for (int k = nambd; k <= ketthuc.Year; k++)
                        {
                            DateTime dulieudau = new DateTime(k, thangbd, ngaybd);
                            int doanhthu = 0;
                            doanhthu = XuLyThongKe.DoanhThuNam(dulieudau);
                            
                          //  if (doanhthu > 0)
                                m_revenueList.Add(new AnnualRevenue(dulieudau.Year.ToString(), doanhthu));
                        }
                    }
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            InitRevenueList();
            this.AnnualRevenueBindingSource.DataSource = m_revenueList;
            this.reportViewer1.RefreshReport();
        }
    }
}